import pandas as pd
import requests

"""
自动化接口测试：
"""


def send_request(func):
    url = "http://localhost:8080/user/sign_in"

    def send(*a, **b):
        ret = func(*a, **b)
        response = requests.post(url=url, json=ret)
        return response

    return send


@send_request
def request_test(dic_data):
    json_data = {
        "accountNumber": dic_data["username"],
        "password": dic_data["password"]
            }
    return json_data


data = pd.read_excel("登录接口测试用例.xlsx", "测试数据")  # 打开表格
hang, lie = data.shape  # 存储行和列
for i in range(hang):
    dic_hang = dict(data.loc[i])
    res = request_test(dic_hang)
    if dic_hang["expected_status"] == res.status_code:
        print("请求成功")
    else:
        print("执行失败")
